//
//  AlertManager.swift
//  MT
//
//  Created by M on 2019/12/17.
//  Copyright © 2019 张强. All rights reserved.
//

import UIKit

public class AlertManager {
    
    /// 弹出性别选择弹窗
    @discardableResult
    class func presentGenderView(selectedType: LocalGenderModel.GenderType, callBack: @escaping GenderAlertView.GenderSelectionCallBack) -> GenderAlertView {
        let p = GenderAlertView(withSelectedGenderType: selectedType, selectedType: callBack)
        p.present()
        return p
    }
    
    /// 弹出礼物选择弹窗
    @discardableResult
    class func presentGiftView(didClickRechargeCallBack: MiTuGiftView.DidClickRechargeCallBack? = nil, selectedGiftCallBack: MiTuGiftView.SelectedGiftCallBack? = nil) -> MiTuGiftView {
        let p = MiTuGiftView(didClickRechargeCallBack: didClickRechargeCallBack, selectedGiftCallBack: selectedGiftCallBack)
        p.present()
        return p
    }
    
    /// 弹出礼物选择弹窗 - 传参 imUserName
    @discardableResult
    class func presentGiftView(isFriend: Bool, imUserName: String, didClickRechargeCallBack: MiTuGiftView.DidClickRechargeCallBack? = nil, selectedGiftCallBack: MiTuGiftView.SelectedGiftCallBack? = nil, didClickSayHiCallBack: @escaping MiTuGiftView.SelectedGiftCallBack, didDismissCallBack: @escaping MiTuGiftView.DidClickRechargeCallBack) -> MiTuGiftView {
        let p = MiTuGiftView(isFriend: isFriend, imUserName: imUserName, didClickRechargeCallBack: didClickRechargeCallBack, selectedGiftCallBack: selectedGiftCallBack, didClickSayHiCallBack: didClickSayHiCallBack, didDismissCallBack: didDismissCallBack)
        p.present()
        return p
    }
    
    ///
    @discardableResult
    class func presentAlertView(message: String, duration: TimeInterval = 1, autoPresent: Bool = true, completion: (() -> Swift.Void)? = nil) -> CenterAlertView {
        let p = CenterAlertView(message: message)
        p.displayDuration = duration
        p.isDismissButtonHidden = true
        if autoPresent {        
            p.present { (_) in
                if let completion = completion {
                    completion()
                }
            }
        }
        return p
    }
    
}

// MARK: ------------------ 分类调用 ----------------------
extension UIViewController {
    
    /// 弹出性别选择弹窗
    @discardableResult
    func presentGenderAlertView(selectedType: LocalGenderModel.GenderType, callBack: @escaping GenderAlertView.GenderSelectionCallBack) -> GenderAlertView {
        return AlertManager.presentGenderView(selectedType: selectedType, callBack: callBack)
    }
    
    /// 弹出礼物选择弹窗
    @discardableResult
    func presentGiftView(didClickRechargeCallBack: MiTuGiftView.DidClickRechargeCallBack? = nil, selectedGiftCallBack: MiTuGiftView.SelectedGiftCallBack? = nil) -> MiTuGiftView {
        return AlertManager.presentGiftView(didClickRechargeCallBack: didClickRechargeCallBack, selectedGiftCallBack: selectedGiftCallBack)
    }
    
    /// 弹出礼物选择弹窗
    @discardableResult
    func presentGiftView(isFriend: Bool, imUserName: String, didClickRechargeCallBack: MiTuGiftView.DidClickRechargeCallBack? = nil, selectedGiftCallBack: MiTuGiftView.SelectedGiftCallBack? = nil, didClickSayHiCallBack: @escaping MiTuGiftView.SelectedGiftCallBack, didDismissCallBack: @escaping MiTuGiftView.DidClickRechargeCallBack) -> MiTuGiftView {
        return AlertManager.presentGiftView(isFriend: isFriend, imUserName: imUserName, didClickRechargeCallBack: didClickRechargeCallBack, selectedGiftCallBack: selectedGiftCallBack, didClickSayHiCallBack: didClickSayHiCallBack, didDismissCallBack: didDismissCallBack)
    }
    
}
